package com.kuang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @program: SpringMVC
 * @description:
 * @author: 陈恩涛
 * @create: 2020-08-01 20:32
 **/
@Controller
public class RestFulController {

    //原来的   :http://localhost:8088/add?a=1&b=2
    //RestFul :http://localhost:8088/add/a/b
    //@PathVariable，让方法参数的值对应绑定到一个URI模板变量上
    //@RequestMapping(value= "/add/{a}/{b}",method = RequestMethod.GET)  --->组合注解：@GetMapping("/add/{a}/{b}")
    //http://localhost:8088/add/1/2
    @GetMapping("/add/{a}/{b}")
    public String test1(@PathVariable int a, @PathVariable String b, Model model) {

        String res = a + b;
        model.addAttribute("msg","结果1为"+res);
        return "test";
    }

    //http://localhost:8088/add/1/3
    @PostMapping("/add/{a}/{b}")
    public String test2(@PathVariable int a, @PathVariable String b, Model model) {

        String res = a + b;
        model.addAttribute("msg","结果2为"+res);
        return "test";
    }
}
